<?php
namespace Admin\Model;
use Think\Model;
/**
 * 分组model
 * @author chl
 *
 */
class GroupModel extends Model
{
	/**
	 * 获取当前数据表中最大的排序ID
	 */
	public function getMaxOId(){
		return  $this->max('orderid')+1;
	}
	
	/**
	 * 新增组别
	 */
	public function addGroup($post_data){
		$data=array(
			"name"		=>	$post_data['name'],
			"ename"		=>	$post_data['ename'],
			"orderid"	=>	$this->getMaxOId()
		);
		$data['id'] = $this->add($data);
		return $data;
	}
	
	/**
	 * 编辑组别
	 */
	public function updateGroup($post_data,$type){
		if($type == 'update'){
			$data=array(
				"name"		=>	$post_data['name'],
				"ename"		=>	$post_data['ename'],
			);
		}else if($type == 'order'){
			
			
		}else if($type == 'selectuser'){
		}
		$where['id']=$post_data['id'];
		$this->where($where)->save($data);
	}	
	 /**
	  * 删除组别
	  * 
	  */
	public function deleteGroup($post_data){
		if(!empty($post_data['id'])){
			$where['id']=$post_data['id'];
			$this->where($where)->delete();
		}
	}
	
	
	public  function getAllGroup()
	{

		$data=$this->order('orderid')->select();
		return $data;
	}
	
	
	
	
	
}